package com.hongfan.common.mp;

import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;

import java.lang.reflect.Type;

/**
 * 反序列化工具，用于处理主键ID
 *
 * @author yjr
 */
public class TableIdDeserializer implements ObjectDeserializer {

    @SuppressWarnings("unchecked")
    @Override
    public <T> T deserialze(DefaultJSONParser parser, Type type, Object o) {
        Integer value = parser.parseObject(Integer.class);
        if (value == null || value == 0) {
            return null;
        }
        return (T) value;
    }

    @Override
    public int getFastMatchToken() {
        return 0;
    }

}